package org.example.netty.test.nio.netty.chat.handler;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.example.netty.test.nio.netty.chat.bean.GetALLGroupNameMessage;
import org.example.netty.test.nio.netty.chat.session.GlobalContent;
import org.example.netty.test.nio.netty.chat.session.UserSession;
import org.example.netty.test.nio.netty.chat.util.NettyChannelUtil;

import java.util.List;
import java.util.Set;

/**
 * @author zp
 * @version 1.0
 * @description: 处理GetALLGroupNameMessage消息
 * @date 2023/4/16 17:28
 */
@Slf4j
public class GetALLGroupNameMessageHandler extends SimpleChannelInboundHandler<GetALLGroupNameMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, GetALLGroupNameMessage msg) throws Exception {
        GlobalContent globalContent = GlobalContent.getInstance();
        Set<String> groupNameList = globalContent.getGroupNameList();
        log.debug("查询所有群聊的消息：{}",msg);
        msg.setAllGroupNames(groupNameList);
        ctx.channel().writeAndFlush(msg);
    }
}
